﻿using Car.NavMesh;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    public MeshFilter meshFilter;

    void Start()
    {
        CarBuildConfig carBuildConfig = new CarBuildConfig();
        carBuildConfig.width = 10;
        carBuildConfig.height = 10;
        carBuildConfig.tileSize = 10;
        carBuildConfig.bmin = Vector3.zero;
        carBuildConfig.bmax = new Vector3(10, 1, 10);
        CarSoloNavMeshInterface.SetBuildConfig(carBuildConfig);

        Mesh sharedMesh = meshFilter.sharedMesh;

        float[] vertexBuffer = new float[sharedMesh.vertexCount * 3];
        for (int i = 0; i < sharedMesh.vertexCount; ++i)
        {
            vertexBuffer[i * 3] = sharedMesh.vertices[i].x;
            vertexBuffer[i * 3 + 1] = sharedMesh.vertices[i].y;
            vertexBuffer[i * 3 + 2] = sharedMesh.vertices[i].z;
        }
        
        CarSoloNavMeshInterface.SetMeshData(vertexBuffer, sharedMesh.vertexCount, sharedMesh.triangles, sharedMesh.triangles.Length / 3);
        CarSoloNavMeshInterface.BuildSoloNavMesh();
    }

    void Update()
    {

    }
}
